use dataset, clear

gen inft = .
replace inft = ft_dem if pid3 == "Democrat"
replace inft = ft_rep if pid3 == "Republican"

gen Br = .
gen Bd = .

replace ideology = -abs(ideology-4)

*** panel (c) coefs by year ***

local X `X' i.education i.race i.region i.agegroup 

su ideology
replace ideology = (ideology - r(min)) / (r(max) - r(min))

levelsof year if !mi(ideology), local(levels)
foreach l of local levels {
 
	reg inft ideology `X' if  year == `l' & pid3 == "Republican" [aw=weight]
	replace Br = _b[ideology] if year == `l'

	reg inft ideology `X' if  year == `l' & pid3 == "Democrat" [aw=weight]
	replace Bd = _b[ideology] if year == `l'

}


collapse Br Bd, by(year pid3)

keep if !mi(Br)

#delimit;

gr tw 
	(sc Bd year if pid3 == "Democrat")
	(fpfit Bd year if pid3 == "Democrat", lpat(dash))
	(sc Br year if pid3 == "Republican", msym(Oh) mfcol(white))
	(fpfit Br year if pid3 == "Republican", lpat(solid))
	,
		plotregion(style(none))
		title("Coefficients")
		ytitle("Impact of moderation on rating")
		xtitle("Year")
		ylab(, angle(horiz))
		legend(
			order(
				1 "Democrats" 2 "Polynomialtrend, Democrats"
				3 "Republicans" 4 "Polynomialtrend, Republicans"
			)
		)
		xlab(1972(8)2016)
		xscale(range(1972 2016))
		name(c, replace)
		;

#delimit cr

gr export "figureA8.eps", replace
